package com.ruoyi.module.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.page.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.module.app.domain.Test;
import lombok.extern.slf4j.Slf4j;
import com.ruoyi.module.app.service.ITestService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.Result;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 系统测试Controller
 *
 * @author mars
 * @date 2022-07-23
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping("/app/test")
public class SysTestController extends BaseController {

    private final ITestService iTestService;

    /**
     * 查询系统测试列表
     */
    @PreAuthorize("@ss.hasPermi('app:test:list')")
    @GetMapping("/list")
    public PageInfo list(Test test) {
        return iTestService.findPageBySpec(test);
    }

    /**
     * 导出系统测试列表
     */
    @PreAuthorize("@ss.hasPermi('app:test:export')")
    @Log(title = "系统测试", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Result export(Test test) {
        LambdaQueryWrapper<Test> lqw = new LambdaQueryWrapper<Test>(test);
        List<Test> list = iTestService.list(lqw);
        ExcelUtil<Test> util = new ExcelUtil<Test>(Test.class);
        return util.exportExcel(list, "test");
    }

    /**
     * 获取系统测试详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:test:query')")
    @GetMapping(value = "/query/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(iTestService.getById(id));
    }

    /**
     * 新增系统测试
     */
    @PreAuthorize("@ss.hasPermi('app:test:add')")
    @Log(title = "系统测试", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody Test test) {
        try {
            return Result.success("新增成功", iTestService.add(test));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    /**
     * 修改系统测试
     */
    @PreAuthorize("@ss.hasPermi('app:test:edit')")
    @Log(title = "系统测试", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result edit(@RequestBody Test test) {
        return toAjax(iTestService.update(test) ? 1 : 0);
    }

    /**
     * 删除系统测试
     */
    @PreAuthorize("@ss.hasPermi('app:test:remove')")
    @Log(title = "系统测试", businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(iTestService.deleteBatch(Arrays.asList(ids)) ? 1 : 0);
    }
}
